package main

import (
	"fmt"

	_ "github.com/jinzhu/gorm/dialects/mysql"

	"github.com/jinzhu/gorm"
)

type Animal struct {
	ID   int64
	Name string
	Age  int64
}
// abc
func main() {
	db, err := gorm.Open("mysql", "root:root@/gormdemo?charset=utf8&parseTime=true&loc=Local")
	if err != nil {
		fmt.Println("connect db error: ", err)
	}
	defer db.Close()
	// 创建结构体封装信息
	var model Animal
	db.Debug().Model(&model).Where("id = ?", 4).Update("name", "update")

	//yongmap封装多个修改条件进行更新
	maps := make(map[string]interface{})
	maps["name"] = "张三"
	maps["age"] = 18
	db.Debug().Model(&model).Where("id = ?", 4).Update(maps)

	// 直接用结构体封装多个条件进行更新
	db.Debug().Model(&Animal{}).Where("id = ?", 11).Update(&Animal{Name: "七七", Age: 52})
}
